<template>
  <div class="app-container">
<!--多选框-->
    <el-form
      label-position="left"
      label-width="80px"
      :rules="rules"
      style="padding:0px 0px 0px 0px"
    >
      <el-row>
        <el-col >
          <span>物料筛选</span>
          <el-form-item label="物料筛选">
            <el-input id="screen" v-model="filterContent" maxlength="150" ></el-input>
          </el-form-item>
          <el-button type="primary" @click="filterhandler()">筛选</el-button>

          <el-form-item style="margin-left:50px">
            <el-badge>
              <el-button type="primary"  @click="fillThisPurchase()" >填充本次购买</el-button>
            </el-badge>
            <el-badge>
              <el-button type="primary"  @click="pushPurchase_back2Sever()" :disabled="canUse === false" >加入购物车</el-button>
            </el-badge>
            <el-badge is-dot :hidden="bB[0]">
              <el-button type="primary"  @click="buyCart()" >我的购物车</el-button>
            </el-badge>
            <el-badge>
              <el-button type="primary" @click="export2buy() ">购买并导出</el-button>
            </el-badge>
          </el-form-item>
        </el-col>
      </el-row>


      <el-row>
        <el-col>
          <span style="margin-left: 3px">A码筛选</span>
          <el-form-item label="A码筛选">
            <el-input id="A_screen" v-model="A_filterContent" ></el-input>
          </el-form-item>
          <el-button type="primary" @click="Acode_filterhandler()">筛选</el-button>
          <el-form-item style="margin-left:53px">
            <el-badge is-dot :hidden="bB[1]" >
              <el-button type="warning"  @click="filterUrgent()" >加急单</el-button>
            </el-badge>
            <el-badge is-dot :hidden="bB[2]">
              <el-button type="success"  @click="getNeedBuyZero()" >需购为0</el-button>
            </el-badge>
            <el-badge is-dot :hidden="bB[3]" >
              <el-button type="success"  @click="getHaveFinished()" >退货</el-button>
            </el-badge>
            <el-badge is-dot :hidden="bB[4]" >
              <el-button type="success" @click="fetchData()">需购大于0</el-button>
            </el-badge>
            <el-badge is-dot :hidden="bB[5]" >
              <el-button type="success" @click="fetchinventory()">库存</el-button>
            </el-badge>
            <el-badge is-dot :hidden="bB[6]" >
              <el-button type="success" @click="fetchAll()">显示全部</el-button>
            </el-badge>
          </el-form-item>
        </el-col>
      </el-row>


      <el-row>
        <el-col>
          <span>列表筛选</span>
          <el-form-item label="列表筛选">
            <el-input id="list_materialno" v-model="A_filterListContent" ></el-input>
          </el-form-item>
          <el-button type="primary" @click="Acode_List_filterHandler()">筛选</el-button>
          <el-form-item style="margin-left: 50px">
            <el-badge>
              <el-button type="danger"  @click="clearCart()" >清空购物车</el-button>
            </el-badge>
            <el-badge>
              <el-button type="danger"  @click="clearAllThisPurchase()" >清除本次购买</el-button>
            </el-badge>
          </el-form-item>
        </el-col>
      </el-row>



    </el-form>

<!--   筛选 -->
    <span> &#12288 </span>

    <el-table
      v-loading = "listLoading"
      :data="list.slice((currentPage-1)*pagesize,currentPage*pagesize)"
      element-loading-text="Loading"
      border
      fit
      max-height="580"
      highlight-current-row
      :default-sort="{prop:'date',order:'scending'}"
      :row-class-name="tableRowClassName"
  >

<!--      <el-table-column type="expand">-->
<!--        <template slot-scope="techlist">-->
<!--          <el-form label-position="left" inline class="demo-table-expand">-->
<!--            <el-form-item label="图号">-->
<!--              <span>{{techlist.row.figureNo}}</span>-->
<!--            </el-form-item>-->
<!--            <el-form-item label="规格">-->
<!--              <span>{{techlist.row.specs}}</span>-->
<!--            </el-form-item>-->
<!--            <el-form-item label="品牌">-->
<!--              <span>{{techlist.row.brand}}</span>-->
<!--            </el-form-item>-->
<!--            <el-form-item label="BOM备注">-->
<!--              <span>{{techlist.row.bomRemark}}</span>-->
<!--            </el-form-item>-->
<!--          </el-form>-->
<!--        </template>-->
<!--      </el-table-column>-->

        <el-table-column align="center" label="物料编号" width="120">
          <template slot-scope="techlist">
            <span>{{techlist.row.materialNo}}</span>
          </template>
        </el-table-column>
        <el-table-column align="center" label="物料名称"  prop="date" width="95">
          <template slot-scope="techlist">
            <span>{{techlist.row.materialName}}</span>
          </template>
        </el-table-column>
        <el-table-column align="center" label="BOM数量" width="95" prop="date">
          <template slot-scope="techlist">
            <span>{{techlist.row.planQuantity}}</span>
          </template>
        </el-table-column>
<!--      <el-table-column label="品牌"  prop="brand" width="150" >-->
<!--        <template slot-scope="techlist">-->
<!--          <span>{{techlist.row.brand}}</span>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--        <el-table-column label="BOM备注"  prop="name" width="150" >-->
<!--          <template slot-scope="techlist">-->
<!--            <span>{{techlist.row.bomRemark}}</span>-->
<!--          </template>-->
<!--        </el-table-column>-->
        <el-table-column label="机台号"  align="center" prop="address">
          <template slot-scope="techlist">
            <span>{{techlist.row.ACode}}</span>
          </template>
        </el-table-column>
        <el-table-column label="采购交期" width="110" align="center" prop="date" sortable>
          <template slot-scope="techlist">
            <span>{{ parseDate( techlist.row.delivery) }}</span>
          </template>
        </el-table-column>
        <el-table-column class-name="status-col" label="已购" width="80" align="center" >
          <template slot-scope="techlist">
            <span>{{techlist.row.purchased}}</span>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="created_at" label="需购" width="80">
          <template slot-scope="techlist">
            <span>{{techlist.row.unpurchased}}</span>
          </template>
        </el-table-column>

      <el-table-column align="center" prop="created_at" label="审批编号" width="220px">
        <template slot-scope="techlist">
          <span>{{techlist.row.approvalCode}}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="本次购买"
        align="center"
        width="150"
      >
        <template slot-scope="scope">
<!--          <el-input id="versiontag" v-model="scope.row.thisPurchase" ></el-input>-->
          <input v-model.lazy="scope.row.thisPurchase" class="el-input__inner"/>
          <span> &#12288 </span>
        </template>
      </el-table-column>

      <el-table-column
        fixed="right"
        label="退货数量"
        align="center"
        width="150">
        <template slot-scope="scope">
<!--          <el-input id="returnQuantity" v-model="scope.row.backGoods" ></el-input>-->
          <input v-model.lazy="scope.row.backGoods" class="el-input__inner" @blur="backgoodsSolve(scope.row)"  aria-placeholder="scope.row.backGoods" />
          <span> &#12288 </span>
        </template>
      </el-table-column>

      <el-table-column
        fixed="right"
        align="center" prop="created_at" label="操作" width="180px" >
        <template slot-scope="techlist">
          <el-button type="primary"size="mini"  @click="showInventoryD(techlist.row)">库存</el-button>
          <el-button type="primary"size="mini"  @click="showD(techlist.row)">其他信息</el-button>
        </template>
      </el-table-column>

<!--      <el-table-column-->
<!--        fixed="right"-->
<!--        align="center" prop="created_at" label="库存备注" width="150" v-if="showInventory">-->
<!--        <template slot-scope="techlist">-->
<!--          <input v-model.lazy="techlist.row.inventoryRemark" class="el-input__inner"   />-->
<!--        </template>-->
<!--      </el-table-column>-->


    </el-table>

    <!--   其他信息 dialog   -->
    <el-dialog title="其他信息" :visible.sync="dialogFormVisible">
      <el-form :model="form">
        <el-row>
          <el-col >
            <el-form-item label="图号" :label-width="formLabelWidth">
              <div style="width: 100px">
                <span class="dialog-font" >图号</span>
                <span>{{form.dialogFigureNumber}}</span>
              </div>
            </el-form-item>
          </el-col>
        </el-row>
       <el-row>
         <el-col>
           <el-form-item label="规格" :label-width=formLabelWidth>
             <span class="dialog-font">规格</span>
             <span >{{form.dialogSpec}}</span>
           </el-form-item>
         </el-col>
       </el-row>
        <el-row>
          <el-col>
            <el-form-item label="品牌" :label-width=formLabelWidth>
              <span class="dialog-font">品牌</span>
              <span>{{form.dialogbrand}}</span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col>
            <el-form-item label="BOM备注" :label-width=formLabelWidth>
              <span class="dialog-font">BOM备注</span>
              <span>{{form.dialogBomRema}}</span>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="dialogFormVisible = false">确 定</el-button>
      </div>
    </el-dialog>

    <!--   库存 dialog   -->
    <el-dialog title="库存操作" :visible.sync="inventorydialogFormVisible">

      <el-form :model="form_inventory">

        <el-row>
          <el-col>
            <span class="dialog-font">需购数量</span>
            <el-form-item  :label-width="formLabelWidth">
              <span>{{form_inventory.needBuy}}</span>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col>
            <span class="dialog-font">库存总数量</span>
            <el-form-item  :label-width="formLabelWidth">
              <span>{{form_inventory.inventory}}</span>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col>
            <span class="dialog-font">本次使用</span>
            <el-form-item  :label-width="formLabelWidth">
              <el-input v-model="form_inventory.thisUse" ></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col>
            <span class="dialog-font">库存备注</span>
            <el-form-item  :label-width="formLabelWidth" >
              <el-input
                type="textarea"
                placeholder="请输入备注"
                v-model="form_inventory.inventoryremark"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>


      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="inventorydialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="useInventory()">保存</el-button>
      </div>

    </el-dialog>



    <el-pagination
      align = "center"
      background
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page.sync="currentPage"
      :page-size="pagesize"
      layout="total, prev, pager, next"
      :total="list.length">
    </el-pagination>

    
  </div>
</template>


<style>
  .el-form-item{
    display: inline-block !important ;
  }

  .el-form-item__label{
    display: none;
    width: 0px !important;
  }
  .dialog-font{
    font-weight: bold;
  }

  .el-form-item__content{
    margin-left: 3px !important;
    margin-right: 3px !important;
  }

  .el-table .warning-row {
    background: oldlace;
  }

  .el-table .success-row {
    background: #f0f9eb;
  }
  .demo-table-expand .el-dialog-c .el-form-item {
    margin-right: 0;
    margin-bottom: 0;
    width: 100%;
  }



</style>


<script>
import { getList } from '@/api/table'
import axios from 'axios';
import Qs from 'qs' //引入json
import { parseDateFull } from '@/api/DateFor';
export default {

  filters: {
    statusFilter(status) {
      const statusMap = {
        published: 'success',
        draft: 'gray',
        deleted: 'danger'
      }
      return statusMap[status]
    }
  },
  data() {
    return {
      bB:[true,true,true,true,true,true,true],
      form_inventory:{
        thisUse:0,
        needBuy:0,
        inventory:0,
        inventoryremark:'',
        id:'',
      },
      form:{
        dialogFigureNumber:'',
        dialogSpec:'',
        dialogbrand:'',
        dialogBomRema:''
      },
      formLabelWidth: '120px',
      dialogFormVisible:false,
      inventorydialogFormVisible:false,
      showInventory: false,
      showBuy:true, //显示本次购买的一列
      canUse: true,
      //用于筛选的数据
      filterContent: '',
      A_filterContent:'',
      A_filterListContent:'',//列表筛选
      //分页数据
      currentPage:1, //初始页
      pagesize:20,    //每页的数据
      rules: {},
      //本次购买:
      //退货数量
      //多选框
      list: [],
      changedList:[], //经过变动的list
      buylist:[],//{购买的material号,机台号，时间，个数，购买还是退货}
      listCopy:[],
      listLoading: false,
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
    setBatch(i){
      this.bB = [true,true,true,true,true,true,true];
      this.bB[i] = false;
    },

    showInventoryD(row){
      debugger
      this.inventorydialogFormVisible = true;
      this.form_inventory.needBuy = row.unpurchased;
      this.form_inventory.inventory = row.inventory;
      this.form_inventory.inventoryremark = row.inventoryRemark;
      this.form_inventory.id = row.id;
      this.form_inventory.thisUse = "";
    },
    showD(row){
      this.dialogFormVisible = true;
      this.form.dialogSpec = row.specs;
      this.form.dialogFigureNumber = row.figureNo;
      this.form.dialogbrand = row.brand;
      this.form.dialogBomRema = row.bomRemark;
    },
    parseDate(date){
      return parseDateFull(date);
    },
    useInventory(){
      var myDate = new Date();
      let datefull = parseDateFull(myDate);
      this.$confirm('确认使用库存？').then( _ => {
        axios.get("/material/changeInventory",{
          params:{
            id: this.form_inventory.id,
            thisUse: this.form_inventory.thisUse,
            inventoryRemark : this.form_inventory.inventoryremark == undefined ? "" : this.form_inventory.inventoryremark + datefull + "\n",
          },
        }).then( res => {
          if(res.data.code == "20000"){
            this.form_inventory.needBuy = this.form_inventory.needBuy - this.form_inventory.thisUse;
            for(var i = 0; i < this.list.length;i++){//让此id的值变掉
              if(this.form_inventory.id == this.list[i].id){
                this.list[i].unpurchased = this.list[i].unpurchased - this.form_inventory.thisUse;
              }
            }
            this.$message({
              message: '用库存成功',
              type: 'success'
            });
          }
          this.inventorydialogFormVisible = false;//消失

          this.listLoading = false;
        }).catch( res => {
              this.listLoading = false;
            }
        )
      }).catch( _ =>{

      })
    },
    //生成唯一15位字符
    getUUIDAndStorage(){
        let num =this.randomWord(false,30);
    },
    randomWord(randomFlag, min, max){
      var str = "",
          range = min,
          arr = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];

      // 随机产生
      if(randomFlag){
        range = Math.round(Math.random() * (max-min)) + min;
      }
      for(var i=0; i<range; i++){
        pos = Math.round(Math.random() * (arr.length-1));
        str += arr[pos];
      }
      return str;
    },
    //页面高亮的处理,传进来row和index
    tableRowClassName({row, rowIndex}) {
      debugger
      if (row.isUrgent == true) {  //如果是加急的话就这样
        return 'warning-row';
      }

      if(row.unpurchased === 0){
        return 'success-row';
      }
      return '';
    },
    //分页
    handleSizeChange: function (size) {
      this.pagesize = size;
      console.log(this.pagesize)  //每页下拉显示数据
    },
    handleCurrentChange: function(currentPage){
      this.currentPage = currentPage;
      console.log(this.currentPage)  //点击第几页
    },
    filterhandler(){
      this.listLoading = true;
      this.canUse = true;
      this.showInventory = false;
      axios.get("/material/filter",{
        params:{
          content: this.filterContent
        },
      }).then( res => {
        if(res.data.code == "20000"){
          let arr = [...JSON.parse(res.data.data)];
          console.log(arr);
          this.list = arr;
          this.showBuy = true;
        }
        this.listLoading = false;
      }).catch( res => {
            this.listLoading = false;
        }
      )
    },
    Acode_List_filterHandler(){
      let tmpList = [];
      let thatList = this.list;
      debugger
      for(var i = 0; i < thatList.length ; i++){
        let No = this.list[i].materialNo;
        let ct = this.A_filterListContent;
        if(No.indexOf(ct) != -1 ){
          debugger
          tmpList.push(this.list[i]);
        }
      }
      this.list = tmpList;
      console.log(this.list);
    },
    Acode_filterhandler(){
      this.canUse = true;
      this.listLoading = true;
      this.showInventory = false;
      axios.get("/material/Acodefilter",{
        params:{
          content: this.A_filterContent
        },
      }).then( res => {
        if(res.data.code == "20000"){
          let arr = [...JSON.parse(res.data.data)];
          console.log(arr);
          this.list = arr;
        }
        this.showBuy = true;
        this.listLoading = false;
      }).catch( res => {
            this.listLoading = false;
          }
      )
    },
    //输入本次购买之后 需购加上 已购减去
    clickbuy(row){

    },
    //点击退货之后 处理退货的内容
    backgoodsSolve(row){
        if(row.backGoods){
          //退货后
          // row.purchased =  String(parseInt(row.purchased) - parseInt(row.backGoods));
          // row.unpurchased = String(parseInt(row.unpurchased) + parseInt(row.backGoods));
          // row.quantity = String( parseInt(row.quantity) - parseInt(row.backGoods));
          // this.changedList.push(row)
          // row.backGoods = '';
        }
    },
    clearCart(){
        this.listLoading = true;
        axios.get('/cart-goods/clearCart',{
          params:{
            userName: localStorage.getItem("userName")
          },
        }).then( res =>{
          if(res.data.code == "20000"){
            let arr = [...JSON.parse(res.data.data)];
            console.log(arr);
            this.list = arr;
            this.canUse = true;
          }
          this.listLoading = false;
        }).catch( res => {
          this.listLoading = false;
        })
    },
    buyCart(){
      this.setBatch(0);
      this.listLoading = true;
      axios.get("/cart-goods/getMyCart",{
        params:{
          userName: localStorage.getItem("userName")
        },
      }).then( res => {
        if(res.data.code == "20000"){
          let arr = [...JSON.parse(res.data.data)];
          console.log(arr);
          this.list = arr;
        }else {
          this.$alert("出现未知错误");
        }
        this.listLoading = false;
      }).catch( res => {
            this.listLoading = false;
            this.logout();
        }
      )
    },
    //获得已完成的，即需购小于0
    getHaveFinished(){
      this.setBatch(3);
      this.listLoading = true;

      axios.get("/material/getHaveFinishedBuy",{
        params:{
          content: this.filterContent
        },
      }).then( res => {
        if(res.data.code == "20000"){
          let arr = [...JSON.parse(res.data.data)];
          console.log(arr);
          this.list = arr;
          this.showBuy = false; //置本次购买那一列为null
          this.showInventory = true;
        }
        this.listLoading = false;
      }).catch( res => {
            this.listLoading = false;
          }
      )
    },
    //获得需购为0的
    getNeedBuyZero(){
      this.setBatch(2);
      this.listLoading = true;
      this.canUse = true;
      this.showInventory = false;
      axios.get("/material/allPruchased",{
        params:{
          content: this.filterContent
        },
      }).then( res => {
        if(res.data.code == "20000"){
          let arr = [...JSON.parse(res.data.data)];
          console.log(arr);
          this.list = arr;
          this.showBuy = false; //置本次购买那一列为null
        }
        this.listLoading = false;
      }).catch( res => {
            this.listLoading = false;
          }
      )
    },
    filterUrgent(){
      this.setBatch(1);
      this.listLoading = true;
      axios.get("/material/urgentfilter",{
        params:{
          content: this.filterContent
        },
      }).then( res => {
        if(res.data.code == "20000"){
          let arr = [...JSON.parse(res.data.data)];
          console.log(arr);
          this.list = arr;
        }
        this.listLoading = false;
      }).catch( res => {
            this.listLoading = false;
          }
      )
    },
    //填充本次购买
    fillThisPurchase(){
      for(var row = 0; row < this.list.length ;row++){
        this.list[row].thisPurchase = this.list[row].unpurchased;
        this.$set(this.list,row,this.list[row]);//更新此行数据
      }
    },
    clearAllThisPurchase(){
      for(var row = 0; row < this.list.length ;row++){
        this.list[row].thisPurchase = '';
        this.$set(this.list,row,this.list[row]);//更新此行数据
      }
    },
    //经过本次购买和退货数量，最终的结果推回后端
    pushPurchase_back2Sever(){
      this.changedList = [];
      this.listLoading = true;
      this.showInventory = false;
      for(var row = 0; row < this.list.length ;row++){
        debugger
        if(this.list[row].thisPurchase){
          this.list[row].purchased =  String(parseInt(this.list[row].thisPurchase) + parseInt(this.list[row].purchased));
          this.list[row].unpurchased = String(parseInt(this.list[row].unpurchased) - parseInt(this.list[row].thisPurchase));
          this.changedList.push(this.list[row])
          this.buylist.push(
              {
                "id":this.list[row].id,
                "materialNo": this.list[row].materialNo,
                "ACode":this.list[row].ACode,
                "time":this.list[row].delivery,
                "buy_num":this.list[row].thisPurchase,
                "back_num":"0",
                "productId":this.list[row].productId,
              })
        }
        if(this.list[row].backGoods){
          this.list[row].purchased =  String(parseInt(this.list[row].purchased) - parseInt(this.list[row].backGoods));
          this.list[row].unpurchased = String(parseInt(this.list[row].unpurchased) + parseInt(this.list[row].backGoods));
          this.changedList.push(this.list[row])
          this.buylist.push(
              {
                "id":this.list[row].id,
                "materialNo": this.list[row].materialNo,
                "ACode":this.list[row].ACode,
                "time":this.list[row].delivery,
                "buy_num":"0",
                "back_num":this.list[row].backGoods,
                "productId":this.list[row].productId,
              })
          // row.quantity = String( parseInt(row.quantity) - parseInt(row.backGoods));   等待上传Bom表平内容
        }
      }
        let data = {"userName":localStorage.getItem("userName"),"buyArrSimple":this.buylist};
        axios.post('/cart-goods/buyMaterial',data)
            .then( res => {
              if(res.data.code == "20000"){
                for(var i=0; i < this.list.length; i++){
                  this.list[i].thisPurchase = '';
                  this.list[i].backGoods = '';
                }
                for(var j = 0; j < this.list.length;j++){
                  this.list[j].thisPurchase = '';
                  this.list[j].backGoods = '';
                }
                this.$alert("更新成功");
                this.buylist=[];
              }else if(res.data.code == "40000"){
                this.$alert(res.data.data);
              }
              this.listLoading = false;
            }).catch( f=>{
          this.listLoading = false;
        } )
    },
    //列表内的值重置到全部的值(重置按钮)
    reset2AllData(){
      this.listLoading = true;
      this.canUse = true;
      this.showInventory = false;
      axios.get("/excel/reset",{
        params:{
          content: this.filterContent
        },
      }).then( res => {
        if(res.data.code == "20000"){
          let arr = [...JSON.parse(res.data.data)];
          console.log(arr);
          this.list = arr;
          this.showBuy = true;
        }
        this.listLoading = false;
      }).catch( res => {
            this.listLoading = false;
          }
      )
    },
    //导出excel
    export2buy(){
      this.canUse = true;
      axios.get('/cart-goods/getPurchaseExcel',{
        responseType: 'blob',
        params:{
          userName:localStorage.getItem("userName"),
        }
      }).then((response) =>{
        if(response == null){
          this.$alert("无此用户,导出失败");
          this.logout();
        }
        let blob = new Blob([response.data],{type:'application/octet-stream'});
        let link = document.createElement('a');
        link.href = window.URL.createObjectURL(blob);
        link.download = "采购.xls";
        link.click();
        // this.list = [];
        this.$alert("导出成功");
      }).catch( f=>{
            this.$alert("尚未登陆,请登录后使用")
            this.logout();
      }
      );
    },
    openM() {
      this.$alert("导出成功");
    },

    fetchData() {
      this.setBatch(4);
      this.listLoading = true;
      axios.get('/material/getFilterMaterial').then( (res) => {
        if (res.data.code == "20000"){
          let arr = [...JSON.parse(res.data.data)];
          this.list = arr;
          debugger
          this.listCopy = this.list;
        }
        this.canUse = true;
        this.listLoading = false;
      }).catch(f =>{
        this.canUse = true;
        this.listLoading = false;
      })
    },
    fetchinventory() {
      this.setBatch(5);
      this.listLoading = true;
      axios.get('/material/inventoryfilter').then( (res) => {
        if (res.data.code == "20000"){
          let arr = [...JSON.parse(res.data.data)];
          this.list = arr;
          debugger
          this.listCopy = this.list;
        }
        this.canUse = true;
        this.listLoading = false;
      }).catch(f =>{
        this.canUse = true;
        this.listLoading = false;
      })
    },
    fetchAll(){
      this.setBatch(6);
      this.listLoading = true;
      axios.get('/material/getAllMaterial').then( (res) => {
        if (res.data.code == "20000"){
          let arr = [...JSON.parse(res.data.data)];
          this.list = arr;
          debugger
          this.listCopy = this.list;
        }
        this.canUse = true;
        this.listLoading = false;
      }).catch(f =>{
        this.canUse = true;
        this.listLoading = false;
      })
    },
    //退出登录
    async logout() {
      localStorage.removeItem('hasLogin');
      this.$router.push(`/login?redirect=${this.$route.fullPath}`);
    },



  }
}
</script>
